//version:1.0.0
  window.save = function () {
        let data = window.vueInstance.$children[0].$children[0].$children[0].$children[1].$children[1].$children[0];
        if (!data.$route.query.ticket && !data.$route.query.projid) return;
        data.formValidate(['form']);
        data.customBackFun();
    };
    export default {
        data() {
            return {
                form:{
                    aae160: {
                        key: '',
                        value: '',
                        p: 'R'
                    },
                    aae041: {
                        value: '',
                        p: 'R'
                    },
                    bac061: {
                        value: '',
                        p: 'D'
                    },
                    bac062: {
                        value: '',
                        p: 'D'
                    },
                    bac063: {
                        value: '',
                        p: 'D'
                    },
                    aae013: {
                        value: '',
                        p: 'E'
                    },
                    aac001: {
                        value: '',
                        p: 'H'
                    },
                    aaz257: {
                        value: '',
                        p: 'H'
                    },
                    aaz159: {
                        value: '',
                        p: 'H'
                    },
                    aaz157: {
                        value: '',
                        p: 'H'
                    },
                    canSave: {
                        value: '',
                        p: 'H'
                    },
                    sum: {
                        value: '',
                        p: 'H'
                    },

                },
                activeName2: '1',
                tableData1: {},
                demo: ['待遇项目','待遇项目名称','金额','扣发月份','扣发金额','停发开始年月','行政区划代码','险种类型','统筹区编码'],
                tableData2: {},
                table2: ['待遇项目','待遇项目名称','对应所属期','扣发金额'],
                tableData3: {},
                demo2: ['待遇变更类型','变更年月','变更原因','经办时间'],
                panel: {},
                show: false,

                rules:{
                    aae160: [
                         {required: true, validator: this.$rules.test_noBlank, trigger: 'change'}

                    ],
                    aae041: [
                         {required: true, validator: this.$rules.test_noBlank, trigger: 'blur'}

                    ],

                },
                codeTypes:{
                    AAE160:[],

                },
                codeTypeFilters:{
                    AAE160:"aaa102 in ('1201','1202','1203','1206','1207','1299')",

                },
                pager: {
	                page: 1,
	                size: 10
            	},
            	total: 0,
            }
        },
        computed: {
            refresh() {
                return localStorage.getItem('refresh') || false;
            },
            functionId() {
                if (this.$store.getters.init.path !== this.$route.path) return;
                if (this.$store.getters.init.mdParam === null || this.$store.getters.init.mdParam === undefined) return;
                if (this.$store.getters.init.mdParam.functionid === undefined) return;
                return this.$store.getters.init.mdParam.functionid;
            },
            backFun() {
                return this.$store.getters.backFun;
            },
            init_show() {
                if (this.$store.getters.init.path !== this.$route.path)  return;
                return this.$store.getters.init.show;
            },
            doInitshow: {
                get: function () {
                    if (this.$store.getters.common === null) return [];
                    if (this.$store.getters.common.path !== this.$route.path) return;
                    return this.$store.getters.common.show;
                },
                set: function (newValue) {
                    if (newValue.path !== this.$route.path) return;
                    return newValue;
                }
            },
            init_formData() {
                if (this.$store.getters.init.path !== this.$route.path)  return;
                return this.$store.getters.init.form;
            },
            doInitformData: {
                get: function () {
                    if (this.$store.getters.common === null) return [];
                    if (this.$store.getters.common.path !== this.$route.path) return;
                    return this.$store.getters.common.formData;
                },
                set: function (newValue) {
                    if (newValue.path !== this.$route.path) return;
                    return newValue;
                }
            },
            init_panel() {
                if (this.$store.getters.init.path !== this.$route.path)  return;
                return this.$store.getters.init.panel;
            },
            doInitpanel: {
                get: function () {
                    if (this.$store.getters.common === null) return [];
                    if (this.$store.getters.common.path !== this.$route.path) return;
                    return this.$store.getters.common.panel;
                },
                set: function (newValue) {
                    if (newValue.path !== this.$route.path) return;
                    return newValue;
                }
            },
            init_tableData1() {
                return this.$store.getters.init.tableData1;
            },
            doInittableData1: {
                get: function () {
                    if (this.$store.getters.common === null) return [];
                    if (this.$store.getters.common.path !== this.$route.path) return;
                    return this.$store.getters.common.tableData1;
                },
                set: function (newValue) {
                    if (newValue.path !== this.$route.path) return;
                    return newValue;
                }
            },
            init_tableData2() {
                return this.$store.getters.init.tableData2;
            },
            doInittableData2: {
                get: function () {
                    if (this.$store.getters.common === null) return [];
                    if (this.$store.getters.common.path !== this.$route.path) return;
                    return this.$store.getters.common.tableData2;
                },
                set: function (newValue) {
                    if (newValue.path !== this.$route.path) return;
                    return newValue;
                }
            },
            init_tableData3() {
                return this.$store.getters.init.tableData3;
            },
            doInittableData3: {
                get: function () {
                    if (this.$store.getters.common === null) return [];
                    if (this.$store.getters.common.path !== this.$route.path) return;
                    return this.$store.getters.common.tableData3;
                },
                set: function (newValue) {
                    if (newValue.path !== this.$route.path) return;
                    return newValue;
                }
            },

        },
        created() {
            let param = {
                path: this.$route.path,
                codeTypes:this.codeTypes,
                codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
                form:this.form,
                tableData1:this.tableData1,
                tableData2:this.tableData2,
                tableData3:this.tableData3,
                panel:this.panel

            };
            if (this.refresh === 'true') {
                this.$store.dispatch('SET_INIT', param);
                sessionStorage.removeItem(this.$route.path);
            }
            if (this.$route.query.keepAlive === undefined) {
                this.$store.dispatch('SET_INIT', param);
            }
        },
        watch: {
            refresh: {
                handler(value) {
                    return value;
                },
            deep: true
            },
            init_show: {
                handler(value) {
                    if (value == undefined) return;
                    this.getshow(value);
                },
                deep: true
            },
            doInitshow: {
                handler(value) {
                    if (value == undefined) return;
                    
                    this.getshow(value);
                },
                deep: true
            },
            init_formData: {
                handler(value) {
                    if (value == undefined) return;
                    this.getformData(value);
                },
                deep: true
            },
            doInitformData: {
                handler(value) {
                    if (value == undefined) return;
                    Object.keys(value).map(item=>{
                        if(value.item && value.item.value){
                            this.$refs.form.validateField(item, (error) => {});
                        }
                    });
                    this.getformData(value);
                },
                deep: true
            },
            init_panel: {
                handler(value) {
                    if (value == undefined) return;
                    this.getpanel(value);
                },
                deep: true
            },
            doInitpanel: {
                handler(value) {
                    if (value == undefined) return;
                    
                    this.getpanel(value);
                },
                deep: true
            },
            doInittableData1: {
                handler(value) {
                    if (value == undefined) return;
                    this.gettableData1(value);
                },
                deep: true
            },
            doInittableData2: {
                handler(value) {
                    if (value == undefined) return;
                    this.gettableData2(value);
                },
                deep: true
            },
            doInittableData3: {
                handler(value) {
                    if (value == undefined) return;
                    this.gettableData3(value);
                },
                deep: true
            },

            backFun: {
                handler(value) {
                    if (value === null) return;
                    this.customBackFun();
                    let backFun = [];
                    backFun = value.split(',');
                    if (backFun.indexOf('rDoInit') >= 0) {
                let codeTypes = {
                    AAE160:[],

                };
                let form = {
                    aae160: {
                        key: '',
                        value: '',
                        p: 'R'
                    },
                    aae041: {
                        value: '',
                        p: 'R'
                    },
                    bac061: {
                        value: '',
                        p: 'D'
                    },
                    bac062: {
                        value: '',
                        p: 'D'
                    },
                    bac063: {
                        value: '',
                        p: 'D'
                    },
                    aae013: {
                        value: '',
                        p: 'E'
                    },
                    aac001: {
                        value: '',
                        p: 'H'
                    },
                    aaz257: {
                        value: '',
                        p: 'H'
                    },
                    aaz159: {
                        value: '',
                        p: 'H'
                    },
                    aaz157: {
                        value: '',
                        p: 'H'
                    },
                    canSave: {
                        value: '',
                        p: 'H'
                    },
                    sum: {
                        value: '',
                        p: 'H'
                    },

                };
                let tableData1= {};
                let tableData2= {};
                let tableData3= {};
                let panel= {};

            let param = {
                path: this.$route.path,
                codeTypes:codeTypes,
                codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
                form:form,
                tableData1:tableData1,
                tableData2:tableData2,
                tableData3:tableData3,
                panel:panel

            };
                        this.$store.dispatch('SET_INIT', param);
                    }
                }
            }
        },
        mounted() {
            if (this.$store.getters.cacheData === null) return;
            if (this.$store.getters.cacheData[this.$route.path] === undefined)  return;
            if (this.$store.getters.cacheData[this.$route.path].path !== this.$route.path) return;
            if (this.$store.getters.cacheData[this.$route.path].form !== undefined) {
                this.getformData(this.$store.getters.cacheData[this.$route.path].form);
            }
            if (this.$store.getters.cacheData[this.$route.path].panel !== undefined) {
                this.getpanel(this.$store.getters.cacheData[this.$route.path].panel);
            }
            if (this.$store.getters.cacheData[this.$route.path].tableData1 !== undefined) {
                this.gettableData1(this.$store.getters.cacheData[this.$route.path].tableData1);
            }
            if (this.$store.getters.cacheData[this.$route.path].tableData2 !== undefined) {
                this.gettableData2(this.$store.getters.cacheData[this.$route.path].tableData2);
            }
            if (this.$store.getters.cacheData[this.$route.path].tableData3 !== undefined) {
                this.gettableData3(this.$store.getters.cacheData[this.$route.path].tableData3);
            }

        },
        beforeRouteLeave(to, from, next) {
            let param = {
                path: this.$route.path,
                codeTypes: this.$store.getters.codeTypes,
                codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
                form:this.form,
                tableData1:this.tableData1,
                tableData2:this.tableData2,
                tableData3:this.tableData3,
                panel:this.panel

            };
            if (from) {
                this.$store.dispatch('SET_CACHEDATA', param);
            }
            next();
        },
        methods: {
            getformData(value) {
                this.form = value;
            },
            getpanel(value) {
                this.panel = value;
            },
            gettableData1(value) {
                this.tableData1 = value;
            },
            gettableData2(value) {
                this.tableData2 = value;
            },
            gettableData3(value) {
                this.tableData3 = value;
            },
            getshow(value) {
                this.show = value;
            },

            clear() {
                let codeTypes = {
                    AAE160:[],

                };
                let form = {
                    aae160: {
                        key: '',
                        value: '',
                        p: 'R'
                    },
                    aae041: {
                        value: '',
                        p: 'R'
                    },
                    bac061: {
                        value: '',
                        p: 'D'
                    },
                    bac062: {
                        value: '',
                        p: 'D'
                    },
                    bac063: {
                        value: '',
                        p: 'D'
                    },
                    aae013: {
                        value: '',
                        p: 'E'
                    },
                    aac001: {
                        value: '',
                        p: 'H'
                    },
                    aaz257: {
                        value: '',
                        p: 'H'
                    },
                    aaz159: {
                        value: '',
                        p: 'H'
                    },
                    aaz157: {
                        value: '',
                        p: 'H'
                    },
                    canSave: {
                        value: '',
                        p: 'H'
                    },
                    sum: {
                        value: '',
                        p: 'H'
                    },

                };
                let tableData1= {};
                let tableData2= {};
                let tableData3= {};
                let panel= {};

            let param = {
                path: this.$route.path,
                codeTypes:codeTypes,
                codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
                form:form,
                tableData1:tableData1,
                tableData2:tableData2,
                tableData3:tableData3,
                panel:panel

            };
                        this.$store.dispatch('SET_INIT', param);
            },

            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
            },
            handleEdit(id) {
                this.dialogFormVisible = true;
            },
            deleteCurrentRow(val){
                this.tableData.Data.splice(this.tableData.Data.findIndex((value,index,ary) => value == val),1);
            },
            formValidate(value){
                if(value && value.length>0){
                    let btn = true;
                    value.forEach((item,index)=>{
                        if(!btn) return
                        this.$refs[item].validate((valid) => {
                            if (valid) {
                                btn = true;
                            } else {
                                btn = false;
                            }
                        });
                    })
                    if(btn) this.$refs.save.btn();
                }
            },

            customBackFun(){//自定义方法体
        },
        },
    }
